package commandes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import bdd.DBS;
import beans.Location;

public class CommandeAjoutLocation implements Commande {
	private String next;

	  public CommandeAjoutLocation(String next) {
	        this.next = next;
	  }

	@Override
	public String execute(HttpServletRequest req) throws Exception {
		HttpSession session = req.getSession(true);
		if(session.getAttribute("droit").equals("administrateur")) {
			
			if(req.getParameter("idlog")!=null){
				DBS db = DBS.getInstance();
				db.getDB_Location().insertLocation(new Location(Integer.parseInt(req.getParameter("idlog")), Integer.parseInt(req.getParameter("idcli")), Integer.parseInt(req.getParameter("duree"))));
			}
			
			return next;
		} else {
			return "index.jsp";
		}
	}

}
